/**
 * vuex管理公共基础类封装
 * Created by hice on 2017/4/1.
 */
import vueutil from '@/common/vue-util'
export const state = {}

export const getters = {}

export const actions = {
  get: async ({ commit }, { url, params, ok, fail, that }) => {
    await that.$http.get(vueutil.url.addUrlParams(params, url))
      .then(res => {
        // success callback
        console.log('ajax-ok:', 11)
        let body = res.data
        commit(ok, {body, that})
      }, res => {
        // error callback
        console.log('ajax-fail:', 22)
        let body = res.data
        commit(fail, {body, that})
      })
      .catch(function (err) {
        console.log('get请求异常:', err);
      })
  },
  post: async ({ commit }, { url, params, ok, fail, that }) => {
    await that.$http.get(url, params)
      .then(res => {
        let body = res.data
        commit(ok, {body, that})
      }, res => {
        let body = res.data
        commit(fail, {body, that})
      })
      .catch(function (err) {
        console.log('post请求异常:', err);
      })
  },
  postSync: ({ commit }, { url, params, ok, fail, that }) => {
    that.$http.get(url, params)
      .then(res => {
        let body = res.data
        commit(ok, {body, that})
      }, res => {
        let body = res.data
        commit(fail, {body, that})
      })
      .catch(function (err) {
        console.log('post请求异常:', err);
      })
  }


}

export const mutations = {
  EMPTY_LIST: (state, { body, that }) => {
    console.log('setEmpty方法')
  }

}
